package com.heima.task;

import com.heima.model.wemedia.pojos.WmNews;
import com.heima.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author itheima
 * @since 2023-01-04
 */
@Component
public class WmNewsPublishTask {

    @Autowired
    private WmNewsService wmNewsService;

    @Scheduled(fixedRate = 5000)
    public void check() {
        System.out.println("定时任务执行中...");
        // 1. 检查那些 未发布，而且发布时间到了的文章（每次提取一篇）
        WmNews wmNews = wmNewsService.check();
        if (wmNews == null) {
            System.out.println("没有可以同步的新闻");
            return;
        }

        // 2. 调用feign接口，进行同步操作
        wmNewsService.refreshArticle(wmNews);
    }

}
